package cn.yanglq.Rss.task;

import cn.yanglq.Rss.core.quartz.QuartzManager;
import cn.yanglq.Rss.core.quartz.TestJob;
import cn.yanglq.Rss.web.model.JobSet;
import cn.yanglq.Rss.web.model.MailSet;
import org.springframework.stereotype.Component;

/**
 * Created by yanglq on 2018/1/17.
 */
@Component
public class JobTask {


    public static String buildTime(JobSet job) {
        return String.valueOf(job.getSecond() != null ? job.getSecond() + " " : "0 ") +
                (job.getMinute() != null ? job.getMinute() + " " : "0 ") +
                (job.getHour() != null ? job.getHour() + " " : "0 ") +
                (job.getDay() != null ? job.getDay() + " " : "* ") +
                (job.getMonth() != null ? job.getMonth() + " " : "* ") +
                (job.getWeek() != null ? job.getWeek() + " " : "? ") +
                (job.getYear() != null ? job.getYear() + " " : "*");
    }


    public static void doQuartz(String jobtime, MailSet set) throws InterruptedException {
        TestJob job = new TestJob();
        String jobs = job.getClass().getName();
        String job_name = "sendMail";
        System.out.println("【任务系统启动】");
        QuartzManager.addJob(job_name, jobs, jobtime,set);
////QuartzManager.addJob(job_name, job, "0 0/3 8-20 ? ? *");
//
//        Thread.sleep(5000);
//        System.out.println("【修改时间】开始(每2秒输出一次)...");
//        QuartzManager.modifyJobTime(job_name, "10/2 * * * * ?");
//        Thread.sleep(6000);
//        System.out.println("【移除定时】开始...");
//        QuartzManager.removeJob(job_name);
//        System.out.println("【移除定时】成功");
//
//        System.out.println("/n【再次添加定时任务】开始(每10秒输出一次)...");
//        QuartzManager.addJob(job_name, jobs, "*/10 * * * * ?");
//        Thread.sleep(60000);
//        System.out.println("【移除定时】开始...");
//        QuartzManager.removeJob(job_name);
//        System.out.println("【移除定时】成功");
    }
}
